home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH9 / SRC / OBJPICT.CLS < prev    next >
Encoding:
Text File  |  1996-05-04  |  3.3 KB  |  130 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "ObjPicture"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = False
  8. Option Explicit
  9.  
  10. Public objects As New Collection
  11.  
  12. Const TYPE_STRING = "3D APF PICTURE"
  13.  
  14.  
  15. ' ************************************************
  16. ' Find an object that contains this point.
  17. ' ************************************************
  18. Function NearestObject(x As Single, y As Single) As Object
  19. Dim obj As Object
  20.        
  21.     ' Find the object.
  22.     For Each obj In objects
  23.         If obj.Contains(x, y) Then
  24.             Set NearestObject = obj
  25.             Exit Function
  26.         End If
  27.     Next obj
  28.     Set NearestObject = Nothing
  29. End Function
  30.  
  31.  
  32. Function ObjectType() As String
  33.     ObjectType = TYPE_STRING
  34. End Function
  35.  
  36.  
  37. ' ************************************************
  38. ' Read the picture from a file using Input.
  39. ' Assume TYPE_STRING has already been read.
  40. ' ************************************************
  41. Sub FileInput(filenum As Integer)
  42. Dim num As Integer
  43. Dim i As Integer
  44. Dim obj As Object
  45. Dim obj_type As String
  46.  
  47.     ' Read the number of objects in the file.
  48.     Input #filenum, num
  49.     
  50.     ' Repeatedly read objects from the file.
  51.     For i = 1 To num
  52.         Input #filenum, obj_type
  53.         Select Case obj_type
  54.             Case TYPE_STRING
  55.                 Set obj = New ObjPicture
  56.             Case "POLYLINE"
  57.                 Set obj = New ObjPolyline
  58.             Case Else
  59.                 Beep
  60.                 MsgBox "Unknown object type """ & obj_type & """.", , vbExclamation
  61.                 Exit Sub
  62.         End Select
  63.         obj.FileInput filenum
  64.         objects.Add obj
  65.     Next i
  66. End Sub
  67.  
  68. ' ************************************************
  69. ' Draw the picture on a Form, Printer, or
  70. ' PictureBox.
  71. ' ************************************************
  72. Sub Draw(canvas As Object, Optional R As Variant)
  73. Dim obj As Object
  74.  
  75.     For Each obj In objects
  76.         obj.Draw canvas, R
  77.     Next obj
  78. End Sub
  79.  
  80. ' ************************************************
  81. ' Write the picture to a file using Write.
  82. ' Begin with TYPE_STRING to identify this object.
  83. ' ************************************************
  84. Sub FileWrite(filenum As Integer)
  85. Dim obj As Object
  86.  
  87.     Write #filenum, TYPE_STRING
  88.     Write #filenum, objects.Count
  89.     
  90.     For Each obj In objects
  91.         obj.FileWrite filenum
  92.     Next obj
  93. End Sub
  94.  
  95. ' ************************************************
  96. ' Apply a nonlinear transformation to the objects.
  97. ' ************************************************
  98. Sub Distort(trans As Object)
  99. Dim obj As Object
  100.  
  101.     For Each obj In objects
  102.         obj.Distort trans
  103.     Next obj
  104. End Sub
  105.  
  106.  
  107. ' ************************************************
  108. ' Apply a transformation matrix which may not
  109. ' contain 0, 0, 0, 1 in the last column to the
  110. ' objects.
  111. ' ************************************************
  112. Sub ApplyFull(M() As Single)
  113. Dim obj As Object
  114.  
  115.     For Each obj In objects
  116.         obj.ApplyFull M
  117.     Next obj
  118. End Sub
  119. ' ************************************************
  120. ' Apply a transformation matrix to the objects.
  121. ' ************************************************
  122. Sub Apply(M() As Single)
  123. Dim obj As Object
  124.  
  125.     For Each obj In objects
  126.         obj.Apply M
  127.     Next obj
  128. End Sub
  129.  
  130.